package com.ymatou.iapi.auth.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.auth.parameter.SignAuthBean;
import com.ymatou.iapi.auth.parameter.UserRemoveTokenRequestDtoBean;
import com.ymatou.iapi.auth.parameter.UserTokenDtoBean;
import com.ymatou.iapi.auth.service.UserRemoveTokenRequestDtoCall;
import com.ymatou.iapi.auth.service.UserTokenDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.mongo.UserTokenWapper;
/**
*删除token
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserRemoveTokenRequestDto{
	private static UserRemoveTokenRequestDtoBean userremovetokenrequestdtoBean;
	private static UserRemoveTokenRequestDtoCall userremovetokenrequestdtoCall;
	private UserTokenWapper userTokenWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除token");
	}

	@Before
	public void caseUp() throws Exception {
		userremovetokenrequestdtoBean=new UserRemoveTokenRequestDtoBean();
		userremovetokenrequestdtoCall=new UserRemoveTokenRequestDtoCall();
		userTokenWapper=new UserTokenWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userremovetokenrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_UserRemoveTokenRequestDto_001() {
		Logger.start(true,"输入正确的token,删除成功");
		try {
			UserRegisterInfoRequestDtoBean cur = new UserRegisterInfoRequestDtoBean();
			cur = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc =JUserCallService.UserRegisterInfoRequestDtoCall(cur); 
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String AccessToken=registerResult.get("Token").getAsString();
			
			userremovetokenrequestdtoBean.setToken(AccessToken);
			userremovetokenrequestdtoCall.setData(userremovetokenrequestdtoBean);
			userremovetokenrequestdtoCall.callService();	
			Logger.verifyEquals(true, userremovetokenrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, userremovetokenrequestdtoCall.getCode(), "验证Code");
			Logger.verifyEquals("ok", userremovetokenrequestdtoCall.getResult(), "验证Result");
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(AccessToken);
			sab.setTokenSource("wxapp");
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_UserRemoveTokenRequestDto_002() {
		Logger.start(false,"输入错误的token,删除失败");
		try {

			userremovetokenrequestdtoBean.setToken("testauto");
			userremovetokenrequestdtoCall.setData(userremovetokenrequestdtoBean);
			userremovetokenrequestdtoCall.callService();	
			Logger.verifyEquals(false, userremovetokenrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, userremovetokenrequestdtoCall.getCode(), "验证Code");
			Logger.verifyEquals("Error", userremovetokenrequestdtoCall.getResult(), "验证Result");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_UserRemoveTokenRequestDto_003() {
		Logger.start(false,"输入已删除的token,删除失败");
		try {

			UserRegisterInfoRequestDtoBean cur = new UserRegisterInfoRequestDtoBean();
			cur = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc =JUserCallService.UserRegisterInfoRequestDtoCall(cur); 
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String AccessToken=registerResult.get("Token").getAsString();
			Logger.comment("创建token，然后删除。");
			Logger.comment("AccessToken："+AccessToken);
			userTokenWapper.deleteData("{\"sId\":\""+AccessToken+"\"}");
			userremovetokenrequestdtoBean.setToken(AccessToken);
			userremovetokenrequestdtoCall.setData(userremovetokenrequestdtoBean);
			userremovetokenrequestdtoCall.callService();	
			Logger.verifyEquals(false, userremovetokenrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, userremovetokenrequestdtoCall.getCode(), "验证Code");
			Logger.verifyEquals("Error", userremovetokenrequestdtoCall.getResult(), "验证Result");			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_UserRemoveTokenRequestDto_004() {
		Logger.start(false,"输入空token,删除失败");
		try {
			userremovetokenrequestdtoBean.setToken(null);
			userremovetokenrequestdtoCall.setData(userremovetokenrequestdtoBean);
			userremovetokenrequestdtoCall.callService();	
			Logger.verifyEquals(false, userremovetokenrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals(200, userremovetokenrequestdtoCall.getCode(), "验证Code");
			Logger.verifyEquals("Error", userremovetokenrequestdtoCall.getResult(), "验证Result");			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}